import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class demo14 {
    public static void main(String[] args) throws IOException {
        //从文件读取字节流
     /*   try (InputStream inputStream = new FileInputStream("./test.txt")) {
            while (true) {
                int count = inputStream.read();
                if (count == -1) {
                    //读完了
                    break;
                }
                System.out.printf("x0%x\n",  count);

            }
        }*/

        //一次性读取多个字节
        try (InputStream inputStream = new FileInputStream("./test.txt")) {
            while (true) {
                byte[] bytes = new byte[3];//这里写多少就会读多少 除非不够
                int n = inputStream.read(bytes);
                System.out.println(n);
                if (n == -1) {
                    //读完了
                    break;
                }
                //针对读到的这些字节进行遍历
                for (int i = 0; i < n; i++) {
                    System.out.printf("0x%x\n", bytes[i]);
                }
            }
        }
    }
}
